package com.zhengdongzulin.zuke.app.main.mine.doorlock

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.DoorLockData
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class DoorLockVm : BaseViewModel() {

    var get_lock_detail: StateLiveData<DoorLockData> = StateLiveData()

    fun get_lock_detail(id: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_LOCK_DETAIL)
                    .add("houseId", id)
                    .toResponse<DoorLockData>()
                    .await()
                get_lock_detail.postValueAndSuccess(r)
            }, {
                assignment(it, get_lock_detail)
            }
        )
    }

    var get_user_arrears: StateLiveData<String> = StateLiveData()

    fun get_user_arrears(id: String) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postJson(Api.GET_USER_ARREARS)
                    .add("houseId", id)
                    .toResponse<String>()
                    .await()
                get_user_arrears.postValueAndSuccess(r)
            }, {
                assignment(it, get_user_arrears)
            }
        )
    }

}